﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Xml;
using System.IO;
using System.Xml.Xsl;
using System.Security.Cryptography;
using System.Text;

namespace green
{
    public static class Constants
    {
        public const string nullSession = "00000000000000000000000000000000";
        public const string jsonResponse = "{{error:{0},message:'{1}',rowsaffected:{2},action: function(){{alert(this.message);}}}}";
        public const string jsonLogin = "{{error:{0},message:'{1}',session:'{2}', action: function(){{alert(this.message);}}}}";
        public static bool IsHmacValid(string key, string msg, string hmac)
        {
            HMACMD5 md5hmac = new HMACMD5(Encoding.UTF8.GetBytes(key));
            byte[] byteHmac = md5hmac.ComputeHash(Encoding.UTF8.GetBytes(msg));
            string S = BitConverter.ToString(byteHmac);
            S = S.Replace("-", "").ToLower();
            return S == hmac.ToLower();
        }
    }

    //public class UserInfo
    //{
    //    private string _login;
    //    private string _Hash;
    //    private string _session;
    //}


    public class PageInfo
    {

        private string _mime;
        private string _body;
        private string _updated;
        private string _name;

        public string PageName
        {
            get { return _name; }
            set { _name = value; }
        }

        public PageInfo(string pName, string mime, string body, string updated)
        {
            _name = pName;
            _mime = mime;
            _body = body;
            _updated = updated;
        }
        public string LastUpdated
        {
            get { return _updated; }
            set { _updated = value; }
        }
        public string Body
        {
            get { return _body; }
            set { _body = value; }
        }
        public string Mime
        {
            get { return _mime; }
            set { _mime = value; }
        }


    }

    public class ImageInfo
    {
        private string _mime;
        private byte[] _body;
        private string _name;

        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }
        public byte[] Body
        {
            get { return _body; }
            set { _body = value; }
        }
        public string Mime
        {
            get { return _mime; }
            set { _mime = value; }
        }
    }
        public class TileInfo
        {
            int _usrId = -1;
            int _usrGroup = -1;

            
            int _tileId = -1;
            int _tileStatus = -1; // flag 1 - query, 2 - action, 3 - action then query
            string _tileName = "";
            string _tileMime = "text/html";
            string _tileQuery = "";
            string _tileXsl = "";
            string _tileAction = "";
            string _tileResponse = "";

            
            public int UsrId
            {
                get { return _usrId; }
                //set { _usrId = value; }
            }
            public int UsrGroup
            {
                get { return _usrGroup; }
                //set { _usrGroup = value; }
            }
            public int TileStatus
            {
                get { return _tileStatus; }
                //set { _tileStatus = value; }
            }

            public string TileAction
            {
                get { return _tileAction; }
                //set { _tileAction = value; }
            }
            public string TileResponse
            {
                get { return _tileResponse; }
                //set { _tileResponse = value; }
            }

            public string TileMime
            {
                get { return _tileMime; }
                //set { _tileMime = value; }
            }


            public XmlReader TileXsl
            {
                get { return XmlReader.Create(new StringReader(_tileXsl)); }
            }

            public string TileQuery
            {
                get { return _tileQuery; }
                //set { _tileQuery = value; }
            }


            public TileInfo(IDataReader dr)
            {
                if (dr.Read())
                {
                    _usrId = Convert.ToInt32(dr["usrId"]);
                    _usrGroup = Convert.ToInt32(dr["usrGroup"]);
                    _tileId = Convert.ToInt32(dr["tileId"]);
                    _tileStatus = Convert.ToInt32(dr["tileStatus"]);
                    _tileName = dr["tileName"].ToString();
                    _tileMime = dr["tileMime"].ToString();
                    _tileQuery = dr["tileQuery"].ToString();
                    _tileAction = dr["tileAction"].ToString();
                    _tileResponse = dr["tileResponse"].ToString();
                    _tileXsl = dr["tileXsl"].ToString();
                }
            }


        }

        
    }

